﻿using System;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace Lesson3_练习题
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 练习一
            //将1~10000赋值给一个二维数组(100行 100列)
            int[,] arr1 = new int[100, 100];
            int index = 1;
            for (int i = 0; i < arr1.GetLength(0); i++)
            {
                for (int j = 0; j < arr1.GetLength(1); j++)
                {
                    arr1[i, j] = index;
                    index++;
                }
            }
            //for (int i = 0; i < arr1.GetLength(0); i++)        
            //{
            //    for (int j = 0; j < arr1.GetLength(1); j++)    
            //    {
            //        Console.Write(arr1[i, j] + " ");
            //    }
            //    Console.WriteLine();
            //}
            #endregion

            #region 练习二
            //将二维数组(4 * 4)的右上半部分置零
            int[,] arr2 = new int[4, 4];
            Random random1 = new Random();
            //赋值
            for (int i = 0;i < arr2.GetLength(0); i++)
            {
                for(int j = 0;j < arr2.GetLength(1); j++)
                {
                    arr2[i, j] = random1.Next(10, 100);
                    if(i <= 1 && j >= 2)
                    {
                        arr2[i, j] = 0;
                    }
                    //Console.Write(arr2[i, j] + " ");
                }
                //Console.WriteLine();
            }

            #endregion

            #region 练习三
            //求二维数组对角线元素的和
            int[,] arr3 = new int[3, 3];
            Random random2 = new Random();
            int sum = 0;
            for (int i = 0; i < arr3.GetLength(0); i++)
            {
                for (int j = 0; j < arr3.GetLength(1); j++)
                {
                    arr3[i, j] = random2.Next(1, 10);
                    if (i == j || i + j == 2)
                    {
                        sum += arr3[i, j];
                    }
                    //Console.Write(arr3[i,j] + " ");
                }
                //Console.WriteLine();
            }
            //Console.WriteLine("该二维数组对角线元素的和为{0}", sum);
            #endregion

            #region 练习四
            //求二维数组(5行 5列)中最大元素的值 及其 行列号
            int[,] arr4 = new int[5, 5];
            Random random3 = new Random();
            int max = 0;
            int row = 0;    //行
            int col = 0;    //列
            for(int i = 0; i < arr4.GetLength(0); i++)
            {
                for (int j = 0; j < arr4.GetLength(1); j++)
                {
                    arr4[i, j] = random3.Next(1, 500);
                    if(max <= arr4[i, j])
                    {
                        max = arr4[i, j];
                        row = i + 1;
                        col = j + 1;
                    }
                    //Console.Write(arr4[i, j] + " ");
                }
                //Console.WriteLine();
            }
            //Console.WriteLine("该数组的最大元素为{0}， 该元素位于{1}行，{2}列", max, row, col);
            #endregion

            #region 练习五
            //申明一个二维数组 数组元素为 0 或 1 要求将含有 1 的行和列 全部置1
            int[,] arr5 = new int[10, 10];
            Random random4 = new Random();
            //赋值
            for(int i = 0; i < arr5.GetLength(0); i++)
            {
                for(int j = 0; j < arr5.GetLength(1); j++)
                {
                    arr5[i, j] = random4.Next(0, 2);
                }
            }
            //输出原数组
            //for(int i = 0;i < arr5.GetLength(0); i++)
            //{
            //    for(int j = 0; j < arr5.GetLength(1); j++)
            //    {
            //        Console.Write(arr5[i, j] + " ");
            //    }
            //    Console.WriteLine();
            //}

            //置1
            for (int i = 0; i < arr5.GetLength(0); i++)
            {
                for (int j = 0; j < arr5.GetLength(1); j++)
                {
                    if (arr5[i, j] == 1)
                    {
                        for (int k = 0; k < arr5.GetLength(0); k++)
                        {
                            arr5[k, j] = 1;
                            arr5[i, k] = 1;
                        }
                    }
                }
            }
            //输出置1后的数组
            //for (int i = 0; i < arr5.GetLength(0); i++)
            //{
            //    for (int j = 0; j < arr5.GetLength(1); j++)
            //    {
            //        Console.Write(arr5[i, j] + " ");
            //    }
            //    Console.WriteLine();
            //}
            #endregion

        }
    }
}